#include <stdio.h>
#include <string.h>
struct stu{
    char name[11];
    char no[11];
    int grade;
};
int main ()
{
    int n=0;
    scanf("%d",&n);
    int i=0;
    struct stu s[n];
    for(i=0;i<n;i++){
        scanf("%s %s %d",&s[i].name,&s[i].no,&s[i].grade);
    }
    int max=101;
    int x1=0;
    int min=-1;
    int x2=0;
    for(i=0;i<n;i++){
        if (max>s[i].grade){
            max=s[i].grade;
            x1=i;
        }
        if (min<s[i].grade){
            min=s[i].grade;
            x2=i;
        }
    }
    printf("%s %s\n",s[x1].name,s[x1].no);
    printf("%s %s",s[x2].name,s[x2].no);
    return 0;
}
